package com.itheima.mapper;


import com.itheima.pojo.Survey;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SurveyMapper {

    /**
     * 查询所有
     * @return
     */
    @Select("select * from survey_info")
    @ResultMap("surveyResultMap")
    List<Survey> selectAll();

    /**
     * 添加数据
     * @param survey
     */
    @Insert("insert into survey_info values(null,#{surveyName},#{surveyDescription},#{startTime},#{endTime},#{status},#{surveySort},#{topFlag},#{createDate},#{updateDate},#{updatorId},#{picId},#{creatorId} )")
    void add(Survey survey);

    /**
     * 批量删除
     * @param ids
     */
    void deleteByIds(@Param("ids") int[] ids);

    /**
     * 删除
     */
    @Delete("delete from survey_info where id = #{id}")
    void delete(@Param("id") int id);

    /**
     * 分页查询
     * @param begin
     * @param size
     * @return
     */
    @Select("select * from survey_info where creator_id = #{creatorId} limit #{begin},#{size} ")
    @ResultMap("surveyResultMap")
    List<Survey> selectByPage(@Param("begin") int begin, @Param("size") int size,@Param("creatorId") int creatorId);

    //管理员专用
    @Select("select * from survey_info limit #{begin},#{size} ")
    @ResultMap("surveyResultMap")
    List<Survey> MselectByPage(@Param("begin") int begin, @Param("size") int size);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from survey_info where creator_id = #{creatorId}")
    int selectTotalCount(@Param("creatorId") int creatorId);

    //管理员专用
    @Select("select count(*) from survey_info ")
    int MselectTotalCount();




    /**
     * 分页条件查询
     * @param begin
     * @param size
     * @return
     */
    List<Survey> selectByPageAndCondition(@Param("begin") int begin,@Param("size") int size,@Param("survey") Survey survey);

    /**
     * 根据条件查询总记录数
     * @return
     */
    int selectTotalCountByCondition(Survey survey);

    @Select("select * from survey_info where status = 1 limit #{begin},#{size}")
    @ResultMap("surveyResultMap")
    List<Survey> selectByStatus(@Param("begin") int begin, @Param("size") int size);

    @Select("select count(*) from survey_info where status = 1")
    int selectByStatusCount();




}
